package com.hankol.winecellar.respository

import androidx.lifecycle.MutableLiveData
import com.baselibrary.extension.checkNotNull
import com.baselibrary.extension.checkValue
import com.baselibrary.net.APIResponse
import com.baselibrary.net.MyHttpUtil
import com.baselibrary.net.result.HttpResult
import com.baselibrary.utils.ContextUtils
import com.baselibrary.utils.SpUtils
import com.hankol.winecellar.api.WineCellarApi
import com.hankol.winecellar.bean.*
import com.baselibrary.base.BasicListBean
import com.hankol.newretail.bean.GoodListBean
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

class WineRequestManager {
    companion object {
        @Volatile
        private var instance: WineRequestManager? = null

        fun getInstance(): WineRequestManager {
            return instance ?: synchronized(this) {
                instance ?: WineRequestManager().also { instance = it }
            }
        }
    }


    //获取经营者所有酒窖列表
    fun reqgetWineryList(phone: String, dealerCode: String, result: MutableLiveData<List<WineryInfoDataBean>>) {
        SpUtils.getInstance().loadUserBean?.data?.token?.let {
            MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqgetWineryList(it, phone, dealerCode).subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<List<WineryInfoDataBean>>(this) {
                override fun onSuccess(t: List<WineryInfoDataBean>, json: String) {
                    if (t != null) result.value = t
                }
            })
        }
    }


    /**
     *经营者中心-功能列表
     */
    fun reqConfigCenterList(dealerCode: String, listData: MutableLiveData<MineCenterMenuBean>) {
        SpUtils.getInstance().loadUserBean?.data?.token?.let {
            MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqConfigCenterList(it, dealerCode)?.subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<MineCenterMenuBean>(this) {
                override fun onSuccess(t: MineCenterMenuBean, json: String) {
                    listData.value = t
                }

                override fun onFailed(message: String?) {
                    listData.value = null
                    super.onFailed(message)
                }

                override fun onError(e: Throwable) {
                    listData.value = null
                    super.onError(e)
                }
            })
        }
    }

    /**
     *获取经营者信息
     */
    fun reqWineryDealerInfo(dealerCode: String, listDataManage: MutableLiveData<WineryManageInfoDataBean>) {
        SpUtils.getInstance().loadUserBean?.data?.token?.let {
            MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqWineryDealerInfo(it, dealerCode)?.subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<WineryManageInfoDataBean>(this) {
                override fun onSuccess(t: WineryManageInfoDataBean, json: String) {
                    listDataManage.value = t
                }

                override fun onFailed(message: String?) {
                    listDataManage.value = null
                    super.onFailed(message)
                }

                override fun onError(e: Throwable) {
                    listDataManage.value = null
                    super.onError(e)
                }
            })
        }
    }

    /**
     *编辑酒窖数据回显
     * wineryId:线上酒窖编号
     * type 0编辑 1预览
     * 附近酒窖列表进入 传type 0
     */
    fun reqgetWineryDataInfo(type: Int, wineryCode: String, dealerCode: String, listData: MutableLiveData<WineryDataInfoBean>) {
        SpUtils.getInstance().loadUserBean?.data?.token?.let {
            //            val wineryCode = SpUtils.getInstance().getCurrentWineryInfo().wineryCode
            val latitude = SpUtils.getFloat(ContextUtils.getCurApplication().applicationContext, "address_Lat", 0f)
            val longitude = SpUtils.getFloat(ContextUtils.getCurApplication().applicationContext, "address_long", 0f)
            MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqgetWineryDataInfo(it, type, dealerCode, wineryCode, latitude, longitude)?.subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<WineryDataInfoBean>(this) {
                override fun onSuccess(t: WineryDataInfoBean, json: String) {
                    listData.value = t
                }

                override fun onFailed(message: String?) {
                    listData.value = null
//                            super.onFailed(message)
                }
            })
        }
    }


    /**
     *私房菜管理 列表
     */
    fun reqPrivateMealList(wineryCode: String, page: Int, size: Int, listData: MutableLiveData<BasicListBean<PrivateMealManageListBean>>) {
        SpUtils.getInstance().loadUserBean?.data?.token?.let {
            MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqPrivateMealList(it, wineryCode, page, size)?.subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<BasicListBean<PrivateMealManageListBean>>(this) {
                override fun onSuccess(t: BasicListBean<PrivateMealManageListBean>, json: String) {
                    listData.value = t
                }

                override fun onFailed(message: String?) {
                    listData.value = null
                    super.onFailed(message)
                }

                override fun onError(e: Throwable) {
                    listData.value = null
                    super.onError(e)
                }
            })
        }
    }


    /**
     *酒窖内限时秒杀 列表
     */
    fun reqSeckillList(shopId: Int, page: Int, size: Int, listData: MutableLiveData<BasicListBean<WineryGoodsSeckillBean>>) {
        if (SpUtils.getInstance().isLogin) {
            MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqSeckillList(shopId, page, size).subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<BasicListBean<WineryGoodsSeckillBean>>(this) {
                override fun onSuccess(t: BasicListBean<WineryGoodsSeckillBean>, json: String) {
                    listData.value = t
                }

                override fun onFailed(message: String?) {
                    listData.value = BasicListBean(emptyList())
                    super.onFailed(message)
                }

                override fun onError(e: Throwable) {
                    listData.value = BasicListBean(emptyList())
                    super.onError(e)
                }
            })
        }
    }

    //酒窖评价列表（全部评价）
    fun requestWineryAllEvaluateList(liveData: MutableLiveData<BasicListBean<WineryEvaluateListBean>>, wineryCode: String, page: Int, size: Int) {
        SpUtils.getInstance().loadUserBean?.data?.token?.let {
            MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).requestWineryAllEvaluateList(it, wineryCode, page, size)?.subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<BasicListBean<WineryEvaluateListBean>>(this) {
                override fun onSuccess(t: BasicListBean<WineryEvaluateListBean>, json: String) {
                    liveData.value = t
                }

                override fun onFailed(message: String?) {
                    liveData.value = BasicListBean(emptyList())
                    super.onFailed(message)
                }

                override fun onError(e: Throwable) {
                    liveData.value = BasicListBean(emptyList())
                    super.onError(e)
                }
            })
        }
    }

    //添加评论
    fun reqAddComment(liveData: MutableLiveData<Boolean>, isEdit: Boolean = false, commentId: Long, wineryCommentDesc: String, wineryCommentImg: String, wineryName: String) {
        SpUtils.getInstance().loadUserBean?.data?.token?.let {
            val wineryCode = SpUtils.getInstance().getCurrentWineryInfo().wineryCode
            var api = MyHttpUtil.getInstance().getApi(WineCellarApi::class.java)
            var observable: Observable<HttpResult<Boolean>>
            if (isEdit) {
                //编辑
                observable = api.reqEditComment(it, commentId, wineryCode, wineryCommentDesc, wineryCommentImg, wineryName)
            } else {
                //新增
                observable = api.reqAddComment(it, wineryCode, wineryCommentDesc, wineryCommentImg, wineryName)
            }
            observable?.subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<Boolean>(this) {
                override fun onSuccess(t: Boolean, json: String) {
                    liveData.value = t
                }

                override fun onFailed(message: String?) {
                    liveData.value = null
                    super.onFailed(message)
                }

                override fun onError(e: Throwable) {
                    liveData.value = null
                    super.onError(e)
                }
            })
        }
    }

    //删除评论
    fun reqDeleteComment(liveData: MutableLiveData<Boolean>, id: Long) {
        SpUtils.getInstance().loadUserBean?.data?.token?.let {
            MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqDeleteComment(it, id)?.subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<Boolean>(this) {
                override fun onSuccess(t: Boolean, json: String) {
                    liveData.value = t
                }

                override fun onFailed(message: String?) {
                    liveData.value = null
                    super.onFailed(message)
                }

                override fun onError(e: Throwable) {
                    liveData.value = null
                    super.onError(e)
                }
            })
        }
    }

    //发布下酒菜
    fun reqAddPrivateMeal(liveData: MutableLiveData<Boolean>, appetizerDesc: String, appetizerImg: String, appetizerName: String, sort: Int) {
        SpUtils.getInstance().loadUserBean?.data?.token?.let {
            val wineryCode = SpUtils.getInstance().getCurrentWineryInfo().wineryCode
            val wineryName = SpUtils.getInstance().getCurrentWineryInfo().wineryName
            MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqAddPrivateMeal(it, wineryCode, wineryName, appetizerDesc, appetizerImg, appetizerName, sort)?.subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<Boolean>(this) {
                override fun onSuccess(t: Boolean, json: String) {
                    liveData.value = t
                }

                override fun onFailed(message: String?) {
                    liveData.value = null
                    super.onFailed(message)
                }

                override fun onError(e: Throwable) {
                    liveData.value = null
                    super.onError(e)
                }
            })
        }
    }

    //编辑下酒菜
    fun reqEditPrivateMeal(liveData: MutableLiveData<Boolean>, id: Int, appetizerDesc: String, appetizerImg: String, appetizerName: String, sort: Int) {
        SpUtils.getInstance().loadUserBean?.data?.token?.let {
            val wineryCode = SpUtils.getInstance().getCurrentWineryInfo().wineryCode
            val wineryName = SpUtils.getInstance().getCurrentWineryInfo().wineryName
            MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqEditPrivateMeal(it, id, wineryCode, wineryName, appetizerDesc, appetizerImg, appetizerName, sort)?.subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<Boolean>(this) {
                override fun onSuccess(t: Boolean, json: String) {
                    liveData.value = t
                }

                override fun onFailed(message: String?) {
                    liveData.value = null
                    super.onFailed(message)
                }

                override fun onError(e: Throwable) {
                    liveData.value = null
                    super.onError(e)
                }
            })
        }
    }

    //删除下酒菜
    fun reqDeletePrivateMeal(liveData: MutableLiveData<Boolean>, id: Int) {
        SpUtils.getInstance().loadUserBean?.data?.token?.let {
            MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqDeletePrivateMeal(it, id)?.subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<Boolean>(this) {
                override fun onSuccess(t: Boolean, json: String) {
                    liveData.value = t
                }

                override fun onFailed(message: String?) {
                    liveData.value = null
                    super.onFailed(message)
                }

                override fun onError(e: Throwable) {
                    liveData.value = null
                    super.onError(e)
                }
            })
        }
    }


    //基础设施列表  type： 0 特色标签 1基础设施标签
    fun reqgetWineryLabelConfig(liveData: MutableLiveData<List<LabelConfigFacilityBean>>, type: Int) {
        SpUtils.getInstance().loadUserBean?.data?.token?.let {
            MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqgetWineryLabelConfig(it, type)?.subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<List<LabelConfigFacilityBean>>(this) {
                override fun onSuccess(t: List<LabelConfigFacilityBean>, json: String) {
                    liveData.value = t
                }

                override fun onFailed(message: String?) {
                    liveData.value = null
                    super.onFailed(message)
                }

                override fun onError(e: Throwable) {
                    liveData.value = null
                    super.onError(e)
                }
            })
        }
    }


    /**
     *获取线上酒窖管理数据
     * wineryCode:线上酒窖编号
     */
    fun reqgetWineryManageData(listData: MutableLiveData<WineryManagerBean>) {
        SpUtils.getInstance().loadUserBean?.data?.token?.let {
            val wineryCode = SpUtils.getInstance().getCurrentWineryInfo().wineryCode
            val dealerCode = SpUtils.getInstance().getCurrentWineryInfo().dealerCode
            val latitude = SpUtils.getFloat(ContextUtils.getCurApplication().applicationContext, "address_Lat", 0f)
            val longitude = SpUtils.getFloat(ContextUtils.getCurApplication().applicationContext, "address_long", 0f)
            MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqgetWineryManageData(it, dealerCode, wineryCode, latitude, longitude)?.subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<WineryManagerBean>(this) {
                override fun onSuccess(t: WineryManagerBean, json: String) {
                    listData.value = t
                }

                override fun onFailed(message: String?) {
                    listData.value = null
                    super.onFailed(message)
                }
            })
        }
    }

    //创建/编辑酒窖数据
    fun reqEditWinery(liveData: MutableLiveData<Boolean>, wineryImg: String, winerySlideshow: String, consumptionPrice: String, startTime: String, endTime: String, wineryDealerPhone: String, wineryDesc: String, wineryFacility: String, wineryFeature: String) {
        SpUtils.getInstance().loadUserBean?.data?.token?.let {
            val wineryCode = SpUtils.getInstance().getCurrentWineryInfo().wineryCode
            val dealerCode = SpUtils.getInstance().getCurrentWineryInfo().dealerCode
            MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqEditWinery(it, wineryCode, wineryImg, winerySlideshow, consumptionPrice, dealerCode, startTime, endTime, wineryDealerPhone, wineryDesc, wineryFacility, wineryFeature)?.subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<Boolean>(this) {
                override fun onSuccess(t: Boolean, json: String) {
                    liveData.value = t
                }

                override fun onFailed(message: String?) {
                    liveData.value = false
                    super.onFailed(message)
                }

                override fun onError(e: Throwable) {
                    liveData.value = false
                    super.onError(e)
                }
            })
        }
    }

    //是否经营者模式
    fun reqIsWineryManager(liveData: MutableLiveData<Boolean>) {
        SpUtils.getInstance().loadUserBean?.data?.token?.let {
            MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqIsWineryManager(it, SpUtils.getInstance().getLoadUserBean().getData().phone.checkValue())?.subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<Boolean>(this) {
                override fun onSuccess(t: Boolean, json: String) {
                    liveData.value = t
                }

                override fun onFailed(message: String?) {
                    liveData.value = false
                    super.onFailed(message)
                }

                override fun onError(e: Throwable) {
                    liveData.value = false
                    super.onError(e)
                }
            })
        }
    }


    //修改经营者状态 0未选择 1社区 2经营者
    fun reqChangeWineryManagerStatus(wineryStatus: Int, liveData: MutableLiveData<Boolean>) {
        SpUtils.getInstance().loadUserBean?.data?.token?.let {
            MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqChangeWineryManagerStatus(it, wineryStatus)?.subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<Boolean>(this) {
                override fun onSuccess(t: Boolean, json: String) {
                    liveData.value = t
                }

                override fun onFailed(message: String?) {
                    liveData.value = null
                    super.onFailed(message)
                }

                override fun onError(e: Throwable) {
                    liveData.value = null
                    super.onError(e)
                }
            })
        }
    }


    /**
     *售卖中，已下架 列表
     * type:类型：0售卖中，1已下架
     */
    fun requestGoodsManagerList(type: Int, dealerCode: String, page: Int, size: Int, listData: MutableLiveData<BasicListBean<GoodsManagerListBean>>) {
        SpUtils.getInstance().loadUserBean?.data?.token?.let {
            MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).requestGoodsManagerList(type, dealerCode, page, size)?.subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<BasicListBean<GoodsManagerListBean>>(this) {
                override fun onSuccess(t: BasicListBean<GoodsManagerListBean>, json: String) {
                    listData.value = t
                }

                override fun onFailed(message: String?) {
                    listData.value = null
                    super.onFailed(message)
                }

                override fun onError(e: Throwable) {
                    listData.value = null
                    super.onError(e)
                }
            })
        }
    }

    /**
     *经营者- 售后订单列表
     */
    fun reqAfterSaleList(dealerCode: String, page: Int, size: Int, liveData: MutableLiveData<BasicListBean<GoodsAfterSaleListBean>>) {
        MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqAfterSaleList(dealerCode, page, size).subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<BasicListBean<GoodsAfterSaleListBean>>(this) {
            override fun onSuccess(t: BasicListBean<GoodsAfterSaleListBean>, json: String) {
                liveData.value = t
            }

            override fun onFailed(message: String?) {
                super.onFailed(message)
            }
        })
    }

    /**
     *  经营者--售后单详情
     */
    fun reqLoadAfterSale(afterSaleId: Long, liveData: MutableLiveData<AfterSalesInfoBean>) {
        MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqLoadAfterSale(afterSaleId).subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<AfterSalesInfoBean>(this) {
            override fun onSuccess(t: AfterSalesInfoBean, json: String) {
                liveData.value = t
            }

            override fun onFailed(message: String?) {
                super.onFailed(message)
            }
        })
    }


    //销售订单列表
    fun reqGoodsOrderList(liveData: MutableLiveData<BasicListBean<GoodsOrderListBean>>, dealerCode: String, status: Int?, keyword: String, page: Int) {
        MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqGoodsOrderList(dealerCode, status, keyword, page, 20).subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<BasicListBean<GoodsOrderListBean>>(this) {
            override fun onSuccess(t: BasicListBean<GoodsOrderListBean>, json: String) {
                liveData.value = t
            }

            override fun onFailed(message: String?) {
                super.onFailed(message)
                liveData.value = null
            }
        })
    }

    //经营者-订单详情
    fun requestOrderDetail(listData: MutableLiveData<GoodsOrderLoadDetailBean>, poId: String) {
        MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).requestOrderDetail(poId).subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<GoodsOrderLoadDetailBean>(this) {
            override fun onSuccess(t: GoodsOrderLoadDetailBean, json: String) {
                if (t.checkNotNull()) listData.value = t
            }

            override fun onError(e: Throwable) {
                listData.value = null
                super.onError(e)
            }

            override fun onFailed(message: String?) {
                listData.value = null
                super.onFailed(message)
            }
        })
    }

    //快递信息
    fun reqLogisticsInfo(poid: String, liveData: MutableLiveData<LogisticeInfoBean>) {
        MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqLogisticsInfo(poid).subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<LogisticeInfoBean>(this) {
            override fun onSuccess(t: LogisticeInfoBean, json: String) {
                liveData.value = t
            }

            override fun onFailed(message: String?) {
                liveData.value = null
                super.onFailed(message)
            }

            override fun onError(e: Throwable) {
                liveData.value = null
                super.onError(e)
            }
        })
    }


    //商品分页列表数字统计
    fun reqGoodsNumStatistics(dealerCode: String, liveData: MutableLiveData<GoodsNumStatisticsBean>) {
        MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqGoodsNumStatistics(dealerCode).subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<GoodsNumStatisticsBean>(this) {
            override fun onSuccess(t: GoodsNumStatisticsBean, json: String) {
                liveData.value = t
            }

            override fun onFailed(message: String?) {
                liveData.value = null
                super.onFailed(message)
            }

            override fun onError(e: Throwable) {
                liveData.value = null
                super.onError(e)
            }
        })
    }

    //修改排序
    fun reqGoodsModifySort(sort: String, spuId: Int, liveData: MutableLiveData<SuccessBean>) {
        MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqGoodsModifySort(sort, spuId).subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<SuccessBean>(this) {
            override fun onSuccess(t: SuccessBean, json: String) {
                liveData.value = t
            }

            override fun onFailed(message: String?) {
                liveData.value = null
                super.onFailed(message)
            }

            override fun onError(e: Throwable) {
                liveData.value = null
                super.onError(e)
            }
        })
    }

    //保存发货信息
    fun reqSaveSendGoodsInfo(kuaiDiCom: String, kuaiDiNum: String, poId: Int, liveData: MutableLiveData<SuccessBean>) {
        MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqSaveSendGoodsInfo(kuaiDiCom, kuaiDiNum, poId).subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<SuccessBean>(this) {
            override fun onSuccess(t: SuccessBean, json: String) {
                liveData.value = t
            }

            override fun onFailed(message: String?) {
                liveData.value = null
                super.onFailed(message)
            }

            override fun onError(e: Throwable) {
                liveData.value = null
                super.onError(e)
            }
        })
    }

    //获取所有快递企业
    fun reqGetAllCompony(liveData: MutableLiveData<MutableList<AllComponyBean>>) {
        MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqGetAllCompony().subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<MutableList<AllComponyBean>>(this) {
            override fun onSuccess(t: MutableList<AllComponyBean>, json: String) {
                liveData.value = t
            }

            override fun onFailed(message: String?) {
                liveData.value = mutableListOf()
                super.onFailed(message)
            }

            override fun onError(e: Throwable) {
                liveData.value = mutableListOf()
                super.onError(e)
            }
        })
    }

    //经营者客户端关闭未支付超时订单
    fun reqOvertimeNoPayCancel(poId: String, liveData: MutableLiveData<SuccessBean>) {
        MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqOvertimeNoPayCancel(poId).subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<SuccessBean>(this) {
            override fun onSuccess(t: SuccessBean, json: String) {
                liveData.value = t
            }

            override fun onFailed(message: String?) {
                liveData.value = null
                super.onFailed(message)
            }

            override fun onError(e: Throwable) {
                liveData.value = null
                super.onError(e)
            }
        })
    }

    //经营者客户端调用,超时未接收的订单修改为接收
    fun reqOvertimeReceive(poId: String, liveData: MutableLiveData<SuccessBean>) {
        MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqOvertimeReceive(poId).subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<SuccessBean>(this) {
            override fun onSuccess(t: SuccessBean, json: String) {
                liveData.value = t
            }

            override fun onFailed(message: String?) {
                liveData.value = null
                super.onFailed(message)
            }

            override fun onError(e: Throwable) {
                liveData.value = null
                super.onError(e)
            }
        })
    }


    //热门城市
    fun reqGetHotCityList(result: MutableLiveData<List<HotCityBean>>) {
        MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqGetHotCityList().subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<List<HotCityBean>>(this) {
            override fun onSuccess(t: List<HotCityBean>, json: String) {
                if (t != null) result.value = t
            }
        })
    }

    //根据店铺id查询商品列表
    fun reqAllStoreGoods(liveData: MutableLiveData<BasicListBean<GoodListBean>>, shopId: Int, page: Int, size: Int) {
        MyHttpUtil.getInstance().getApi(WineCellarApi::class.java).reqAllStoreGoods(shopId, page, size).subscribeOn(Schedulers.newThread())?.observeOn(AndroidSchedulers.mainThread())?.subscribe(object : APIResponse<BasicListBean<GoodListBean>>(this) {
            override fun onSuccess(t: BasicListBean<GoodListBean>, json: String) {
                liveData.value = t
            }

            override fun onFailed(message: String?) {
                super.onFailed(message)
                liveData.value = null
            }
        })
    }

}